package org.qengine.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.qengine.entity.QuestionEntity;

import java.util.List;
import java.util.Map;

@Mapper
public interface QuestionDao extends BaseMapper<QuestionEntity>{
    /****新增****/
    @Insert("INSERT INTO question (typeID, courseID, knowledgeID, dLevel, questionStem, questionAnswer, answerCount, wrongCount) VALUES (#{typeID}, #{courseID}, #{knowledgeID}, #{dLevel}, #{questionStem}, #{questionAnswer}, #{answerCount}, #{wrongCount})")
    int addQuestion(QuestionEntity questionEntity);
    /****删除****/
    @Insert("insert into question(ID, typeID, courseID, knowledgeID, dLevel, questionStem, questionAnswer, answerCount, wrongCount) values(#{id}, #{typeID}, #{courseID}, #{knowledgeID}, #{dLevel}, #{questionStem}, #{questionAnswer}, #{answerCount}, #{wrongCount})")
    void addQuestionWithId(QuestionEntity questionEntity);
    int deleteQuestionById(int id);
    int deleteQuestionByCourseId(int courseId);
    int deleteQuestionByCourseIdAndKnowledgeId(int courseID, int knowledgeID);
    /****修改****/
    @Update( "UPDATE question SET typeID = #{typeID}, courseID = #{courseID}, knowledgeID = #{knowledgeID}, dLevel = #{dLevel}, questionStem = #{questionStem}, questionAnswer = #{questionAnswer}, answerCount = #{answerCount}, wrongCount = #{wrongCount} WHERE id = #{id}" )
    int updateQuestionById(QuestionEntity questionEntity);
    /****查询****/
    @Select("select * from question where id = #{id}")
    List<QuestionEntity> getQuestionById(int id);
    List<QuestionEntity> selectAllQuestions();
    List<QuestionEntity> selectQuestionByCourseId(int courseId);
    List<QuestionEntity> selectQuestionByCourseIdAndTypeId(int courseID, int typeID);
    @Select(" select * from question where typeID = #{typeId} and courseID = #{courseId} and knowledgeID = #{knowledgeId} and dLevel = #{dLevel} ")
    List<QuestionEntity> selectQuestionByTrainingPaperRules(int typeId, int courseId, int knowledgeId, int dLevel);
    //使用动态查询
    @Select("SELECT id, content, wrongCount FROM question WHERE wrongCount > 0")
    List<QuestionEntity> findWrongQuestions();
    List<QuestionEntity> selectQuestionByDynamicRules(Map<String, Object> body);
    List<QuestionEntity> selectQuestionByAlternativeRules(int typeId, Integer courseId, int dLevel);
}
